import { defineStore } from 'pinia'
import request from '@/utils/request'

const token = localStorage.getItem('pax_token')
export const useServer = defineStore('servers', {
  state: () => ({
    serverList: [], // 存储 Token
  }),
  actions: {
    // 同步 action：直接修改 token
    setServerList(data) {
      this.serverList = data
    },
    async fetchServerList() {
      try {
        const response = await request.get("pax/server_view", {
            headers: { "Authorization": token }
          })
        this.serverList = response.data
        console.error('获取列表成功:', response)
      } catch (error) {
        console.error('获取列表失败:', error)
        this.serverList = [] // 失败时重置为空数组
      }
    }
  }
  
})